<template>
  <!--使用验证记录-->
  <div class="jilu">
    <div class="search">
      <p>
        <input type="text" placeholder="搜索" v-model="content">
        <img src="../../../assets/search.png" alt="" width="16"
             @click="goSearch()">
      </p>
    </div>
    <div class="search">
      <wv-cell
        title=""
        :value="startTime"
        is-link
        @click="openPicker('startDatePicker')"
      />
      <wv-datetime-picker
        type="date"
        ref="startDatePicker"
        :endDate="startDate"
        v-model="beginDate"
        @confirm="onConfirmStartDate"
      />
      <div class="line"></div>
      <wv-cell
        title=""
        :value="endTime"
        is-link
        @click="openPicker('endDatePicker')"
      />
      <wv-datetime-picker
        type="date"
        ref="endDatePicker"
        :endDate="endDate"
        v-model="finshDate"
        @confirm="onConfirmEndTime"
      />
      <span style="margin-top: 10px;font-size: 15px">核验总数：{{totalNum}}</span>
    </div>

    <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
      <wv-group
        v-infinite-scroll="getList"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <wv-panel class="lists">
          <wv-media-box thumb="" v-for="(item,index) in list" :title="item.serverName"
                        :description="'登录账号：'+item.accountName" :key="index" type="text">
            <ul class="weui-media-box__info" slot="box_ft">
              <li v-if="item.checkType==1 || item.checkType==3">会员姓名：{{item.userName}}</li>
              <li v-if="item.checkType==1 || item.checkType==3">会员手机号：{{item.mobile}}</li>
              <li v-if="item.vipCardNo">会员卡号：{{item.vipCardNo}}</li>
              <li v-if="item.remark">备注：{{item.remark}}</li>
              <li>{{item.createDate}} <span>×{{item.useNum}}</span></li>
            </ul>
          </wv-media-box>
        </wv-panel>
      </wv-group>
    </div>
    <p style="position: fixed; bottom: 0;color: #ffbe00;width: 100%;text-align: center;font-size: 18px">
      {{page}}/{{pages}}
    </p>
  </div>
</template>

<script type="text/ecmascript-6">
  import {employeeCheckRecordList} from '../../../../test/unit/http'

  export default {
    name: '',
    props: {},
    data() {
      return {
        startDate: new Date(),
        endDate: new Date(),
        beginDate: new Date(),
        finshDate: new Date(),
        content: '',
        createDate: '',
        page: 1,
        rows: 10,
        pages: 0,
        list: [],
        totalNum: 0,
        wrapperHeight: 0,
        loading: false,
      };
    },
    methods: {
      openPicker(ref) {
        this.$refs[ref].open()
      },
      goSearch() {
        this.page = 1;
        this.list = [];
        this.getList()
      },
      getList() {
        this.loading = true;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        employeeCheckRecordList(params).then(res => {
          console.log(res);
        if (res.code == 100) {
          let data = res.object;
          let list = data.pqGrid.rows;
          let pages = data.pqGrid.pages;
          this.pages = pages;
          let page = data.pqGrid.page;
          this.page = page;
          let totalNum = data.totalNum;
          this.totalNum = totalNum;
          if (list.length > 0) {
            this.list = this.list.concat(list);
          }
        }
        if (this.page < this.pages) {
          this.page++;
          this.loading = false
        } else {
          this.loading = true
        }
      }).catch(err => {
    console.log(err);
  });
      },
      onConfirmStartDate(value) {
        let message = '';
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          if (month < 10) {
            month = '0' + month;
          }
          let date = value.getDate();
          if (date < 10) {
            date = '0' + date;
          }
          message = `${year}-${month}-${date}`
        } else {
          message = value
        }
        this.page = 1;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        this.getSearchList(params)
      },
      onConfirmEndTime(value) {
        let message = '';
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          if (month < 10) {
            month = '0' + month;
          }
          let date = value.getDate();
          if (date < 10) {
            date = '0' + date;
          }
          message = `${year}-${month}-${date}`
        } else {
          message = value
        }
        this.page = 1;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        this.getSearchList(params)
      },
    },
    created() {
    },
    filters: {
      datetimeFilter(value, type) {
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          let date = value.getDate();
          let hour = value.getHours();
          let minute = value.getMinutes();
          return type === 'date' ? `${year}/${month}/${date}` : `${year}/${month}/${date} ${hour}:${minute}`
        } else {
          return value
        }
      }
    },
    computed: {
      startTime: {
        get: function () {
          let value = this.beginDate;
          let message = '';
          if (value !== null && typeof value === 'object') {
            let year = value.getFullYear();
            let month = value.getMonth() + 1;
            if (month < 10) {
              month = '0' + month;
            }
            let date = value.getDate();
            if (date < 10) {
              date = '0' + date;
            }
            message = `${year}-${month}-${date}`;
          } else {
            message = value;
          }
          return message;
        },
        set: function (date) {
          return date;
        }
      },
      endTime: {
        get: function () {
          let value = this.finshDate;
          let message = '';
          if (value !== null && typeof value === 'object') {
            let year = value.getFullYear();
            let month = value.getMonth() + 1;
            if (month < 10) {
              month = '0' + month;
            }
            let date = value.getDate();
            if (date < 10) {
              date = '0' + date;
            }
            message = `${year}-${month}-${date}`;
          } else {
            message = value;
          }
          return message;
        },
        set: function (date) {
          return date;
        }
      }
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">

  .weui-panel:before {
    border-top: none;
  }

  .lists {
    text-align: left;

    .weui-media-box__info span {
      position: absolute;
      right: 25px;
      top: 20px;
      font-size: 15px;
      color: #666;
    }

    .weui-media-box__info {
      li {
        color: #666;
        margin-bottom: 15px;
        font-size: 13px;
      }

      li:last-child {
        font-size: 12px;
        color: #999;
      }
    }
  }

  .search {
    position: relative;
    width: 95%;
    margin: 10px auto;
    display: flex;

    input {
      width: 92%;
      border: 1px solid #eee;
      box-shadow: 0 3px 4px rgba(17, 17, 17, 0.05);
      border-radius: 7px;
      height: 25px;
      line-height: 25px;
      padding: 10px;
      color: #111;
    }

    .searchicon {
      position: absolute;
      right: 20px;
      top: 16px;
    }

    p {
      flex: 0 100%;
      position: relative;
      margin-right: 5px;

      img {
        position: absolute;
        right: 20px;
        top: 16px;
      }
    }

  }
</style>
